package jzOffer;

  class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
  }
public class Num26 {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if(A==null || B==null) return false;
        return isSameTree(A,B) || isSubStructure(A.left,B) || isSubStructure(A.right,B);
    }
    public boolean isSameTree(TreeNode p, TreeNode q){
        if(q==null) return true;
        if(p==null || p.val!=q.val) return false;
        return isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
    }
}
